package shengchanxiaofeizhe;

public class Consumer implements Runnable{
    @Override
    public void run() {
        while (true){
            WareHouse.lock.lock();

            if(WareHouse.mark){
                // 如果有包子
                System.out.println("消费者-吃包子");
                WareHouse.mark= false;
                // 唤醒生产者
                WareHouse.producer.signal();
            }else{
                // 唤醒生产者
                WareHouse.producer.signal();
                // 自己休息
                try {
                    WareHouse.consumer.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

            WareHouse.lock.unlock();
        }
    }
}
